//
//$Id: islsp_gn.h 663 2011-02-26 10:41:57Z andrew.tsyganov $
#pragma once

#include "islsp_solution.h"
#include "islsp_mlf_sr.h"
#include "islsp_mlf_kf.h"
#include "islsp_history.h"

#include "solvers/sa/sa_common.h"
#include "solvers/user/user_omp.h"

//__________________________________________________________________________________
template<>
struct solution<Islsp_Solution, user_tag>:
    public Islsp_Solution
{
};

template<class T>
class GN: public user_OMP<T, GN<T> >
{
protected:
	int max_step_;

public:
    template<class V>
    void accept(V& v)
    {
        v(VAR_(max_step), 100);
    }

    virtual void user_Solve(Solution_Pool<typename TEnvironment::TSolution>& pool,
        typename TEnvironment::TStatistics& stat, int np)
    {
        Array<double> c, t0 = current_.get_T();
        size_t n = current_.get_T().size();
        c.resize(n);

        TCostType old_cost, new_cost;
        
        size_t i = 0;

		do
        {
			current_.evaluate(env_, rnd_);
            old_cost = current_.get_Cost(); 

			if (env_->cfg_.method_ == "mlf_kf")  
			{
				current_.evaluate_Correction_MLF_KF(env_, c);
			}
			else
			{
				if (env_->cfg_.method_ == "mlf_sr")
				{
					current_.evaluate_Correction_MLF_SR(env_, c);
				}
			}

		   for (size_t k = 0; k < n; ++k)
		    {
                current_.get_T()[k] -= c[k];
			}

            current_.Changed();
			current_.evaluate(env_, rnd_);
			new_cost = current_.get_Cost(); 
		   			
            stat.update(i, rank_, *this, *this->env_);
            ++i;
        }
        while (i < max_step_);
    }
};
//__________________________________________________________________________________

//EOF!
